<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>小鱼ADMIN</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/public/static/css/font.css">
    <link rel="stylesheet" href="/public/static/css/bgadmin.css">
    <link href="/public/static/lib/address/css/city-picker.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="/public/static/js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/public/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/public/static/js/bgadmin.js"></script>
    <script type="text/javascript" src="/public/static/js/jquery.form.js"></script>  
</head>

<body>
    <div class="bg-body">
		<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief" style="margin-top: -12px">
		  <ul class="layui-tab-title">
			<li class="layui-this">会员资料</li>
			<li onclick="loadIframe('iframe_editTask', './editTask.html?id={$id}')">编辑任务</li>
			<li onclick="loadIframe('iframe_callRecord', './callRecord.html?id={$id}')">通话记录</li>
		  </ul>
		  <div class="layui-tab-content">
			<div class="layui-tab-item layui-show">
			  <div class="layui-row">
				  <div class="layui-form-item">
		            <div class="layui-inline">
		            	<button class="layui-btn layui-btn-small" onclick="transferCustomer();"><i class="layui-icon">&#xe641;</i>转交号码池</button>
		            	<button class="layui-btn layui-btn-small" onclick="resetCallFailedNum();"><i class="layui-icon">&#xe641;</i>重置未接号码</button>
		            </div>
				  </div>
			  </div>
				<div class="layui-row">
					<form class="layui-form ">
					  <div class="layui-form-item">
						<div class="layui-inline">
						  <label class="layui-form-label" onclick="clearInput ('name')">客户姓名：</label>
						  <div class="layui-input-inline">
							<input type="text" name="name" lay-verify="" id="name" autocomplete="off" class="layui-input">
						  </div>
						</div>
						<div class="layui-inline">
						  <label class="layui-form-label" onclick="clearInput ('phone')">手机：</label>
						  <div class="layui-input-inline">
							<input type="text" name="phone" id= "phone" lay-verify="" autocomplete="off" class="layui-input">
						  </div>
						</div>
						<div class="layui-inline">
						  <label class="layui-form-label" onclick="clearInput ('customer_code')">客户编码：</label>
						  <div class="layui-input-inline">
							<input type="text" name="customer_code" id= "customer_code" lay-verify="" autocomplete="off" class="layui-input">
						  </div>
						</div>
						<div class="layui-inline">
						  <label class="layui-form-label" onclick="clearInput ('import_mark')">导入标记：</label>
						  <div class="layui-input-inline">
							<input type="text" name="import_mark" id= "import_mark" lay-verify="" autocomplete="off" class="layui-input">
						  </div>
						</div>
						<a class="layui-btn layui-btn-small"  style="margin-bottom: 10px;" id="search"  lay-submit="" lay-filter="search"><i class="layui-icon" >&#xe615;</i></a>
					  </div>
					</form>
				</div>
				<table class="layui-table" lay-data="{id: 'customer_code', height:480, url:'/index.php/crm/Outboundmanager/saleSourceData?id={$id}', page:true, limit:10, limits:[10,20,30,50]}" lay-filter="demo">
					<thead>
					<tr>
					  <th lay-data="{checkbox:true, fixed: true}"></th>
					  <th lay-data="{field:'customer_code', align:'center', width:180, fixed: 'left'}">会员编码</th>
					  <th lay-data="{field:'name', width:100, align:'center', fixed: 'left'}">会员姓名</th>
					  <th lay-data="{field:'phone1', width:120, align:'center'}">客户手机</th>
					  <th lay-data="{field:'calledflag', width:120, align:'center'}">呼叫状态</th>
					  <th lay-data="{field:'import_mark', width:150, align:'center'}">导入标记</th>
					  <th lay-data="{field:'address', width:250, align:'center'}">导入地址</th>
					  <th lay-data="{field:'createtime', width:150, align:'center'}">创建时间</th>
					  <!-- <th lay-data="{fixed: 'right', width:80, align:'center', toolbar: '#barDemo'}">操作</th> -->
					</tr>
					</thead>
				</table>
				   
				<script type="text/html" id="barDemo">
					<a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
				</script>
			</div>
			<div class="layui-tab-item">
				<iframe id="iframe_editTask" src="" style="width:100%;height:650px;" scrolling="auto" frameborder="0" ></iframe>
			</div>
			<div class="layui-tab-item">
				<iframe id="iframe_callRecord" src="" style="width:100%;height:650px;" scrolling="auto" frameborder="0" ></iframe>
			</div>
		  </div>
		</div>
	</div>
	<div class="bg-body" style="margin-top: -20px">
		<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
		  <ul class="layui-tab-title">
			<li class="layui-this">任务控制</li>
			<!-- <li >坐席监控</li>
			<li >当前通话</li>
			<li >等待队列</li> -->
		  </ul>
		  <div class="layui-tab-content" style="height: 200px;">
			<div class="layui-tab-item layui-show">
				<form class="layui-form ">
					<div class="layui-inline">
						<label class="layui-form-label" style="width: 130px;">编号：</label>
						<div class="layui-input-inline" style="width: 100px;height: 38px;line-height: 38px;">{$id}</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label" style="width: 130px;">任务进度：</label>
						<div class="layui-input-inline" style="width: 100px;height: 38px;line-height: 38px;">{$ST.progress}%</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label" style="width: 130px;">号码总量：</label>
						<div class="layui-input-inline" style="width: 100px;height: 38px;line-height: 38px;">{$ST.total}</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label" style="width: 130px;">已呼叫总量：</label>
						<div class="layui-input-inline" style="width: 100px;height: 38px;line-height: 38px;">{$ST.db_calledCount}</div>
					</div>

					<div class="layui-inline">
						<label class="layui-form-label" style="width: 130px;">正在呼叫数量：</label>
						<div class="layui-input-inline" style="width: 100px;height: 38px;line-height: 38px;" id="ringingCount">0</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label" style="width: 130px;">正在通话数量：</label>
						<div class="layui-input-inline" style="width: 100px;height: 38px;line-height: 38px;" id="connectingCount">0</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label" style="width: 130px;">队列中等待的数量：</label>
						<div class="layui-input-inline" style="width: 100px;height: 38px;line-height: 38px;" id="waitQueue">0</div>
					</div>
					
					<div class="layui-inline">
						<label class="layui-form-label" style="width: 130px;">当前任务并发数：</label>
						<div class="layui-input-inline">
							<input type="text" name="concurrent" lay-verify="" id="concurrent" value="{$ST.concurrence}" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-input-inline" style="width: 100px;height: 38px;line-height: 38px;">
							<a class="layui-btn" onclick="concurrenceChange()">更改</a>
						</div>
					</div>

					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">项目状态：</label>
							<div class="layui-input-block">
								<input type="radio" name="status" value="on" lay-filter="status" title="开启" {eq name="ST.status" value="on"}checked{/eq} >
								<input type="radio" name="status" id="on_status" lay-filter="status" value="off"  title="关闭" {eq name="ST.status" value="off"}checked{/eq} >
							</div>
						</div>
					</div>
					
				</form>
			</div>
			<div class="layui-tab-item">
				22
			</div>
			<div class="layui-tab-item">
				<table class="layui-table" lay-data="{id: 'id', height:'full-300', url:'/index.php/crm/Servicecustomer/customerDataList_', page:true, limit:10, limits:[10,20,30,50]}">
				  <thead>
				  <tr>
				    <th lay-data="{checkbox:true, fixed: true}"></th>
				    <th lay-data="{field:'id', align:'center', width:180, fixed: 'left'}">通道</th>
				    <th lay-data="{field:'name', width:100, align:'center', fixed: 'left'}">等待号码</th>
				    <th lay-data="{field:'create_name', width:100, align:'center', fixed: 'left'}">等待时间</th>
				  </tr>
				  </thead>
				</table>
			</div>
			<div class="layui-tab-item">
				<table class="layui-table" lay-data="{id: 'id', height:'full-300', url:'/index.php/crm/Servicecustomer/customerDataList_', page:true, limit:10, limits:[10,20,30,50]}">
				  <thead>
				  <tr>
				    <th lay-data="{checkbox:true, fixed: true}"></th>
				    <th lay-data="{field:'id', align:'center', width:180, fixed: 'left'}">通道</th>
				    <th lay-data="{field:'name', width:150, align:'center', fixed: 'left'}">号码</th>
				    <th lay-data="{field:'create_name', width:150, align:'center', fixed: 'left'}">通话时间</th>
				    <th lay-data="{field:'create_name', width:150, align:'center', fixed: 'left'}">接听分机号</th>
				  </tr>
				  </thead>
				</table>
			</div>
		  </div>
		</div>
	</div>
</body>
<!-- <script type="text/javascript" src="/public/static/crm/js/customer/editCustomer.js"></script> -->
<script src="/public/static/lib/address/js/city-picker.data.js"></script>
<script src="/public/static/lib/address/js/city-picker.js"></script>
<script src="/public/static/lib/address/js/main.js"></script>
<script>
	var id = '{$id}';
    function loadIframe (id, url) {
        if ($('#'+id).attr('src') == "") {
            $('#'+id).attr('src', url);
        }
    }

    $(document).on('dblclick', '.layui-table>tbody>tr', function (){
        var customer_code = $(this).children('td:eq(1)').text();
        if (!customer_code) return false;
        bg_full_show('编辑资料','/index.php/crm/Callplatform/editMyCustomer.html?customer_code='+customer_code+'&id='+id)
    })

    var layer = layui.layer;
 
	
	layui.use('table', function(){
        var table = layui.table;
	});
	
	function statusChange(obj){
		var status = obj.value;
		var url = "/index.php/crm/Outboundmanager/changeDialManager";
		var id = {$id};
		var concurrence = $("#concurrent").val();
		$.ajax({
			type: 'GET',
			url: url,
			data: {id:id,status:status,concurrence:concurrence},
			success: function(result){
				// alert(JSON.stringify(result));
				result = eval('('+result+')')
				if (result.success) {  
				    layer.alert(result.msg, {icon: 6}, function(index){
				        layer.close(index);
				    });
				} else {  
				    layer.alert(result.msg, {icon: 5}, function(index){
				        layer.close(index);
				    });
				}
			}
		});
	}
	
	
	layui.use('form', function(){
		var form = layui.form;
		form.on('radio(status)', function(data){
		  //alert(data.value); //被点击的radio的value值
		  statusChange(data);
		}); 
	});


	/**
	 * 转交客户资料资料
	 */
	function transferCustomer () {
	    layui.use('table', function(){
	        var table = layui.table;
	        var checkStatus = table.checkStatus('customer_code');
	        if (checkStatus.data.length < 1) {
	            layer.alert('请选择需要被转交的客户', {icon: 5}, function(index){
	                layer.close(index);
	            });
	            return false;
	        }
	        var customer_codes = '';
	        for (var i = 0; i < checkStatus.data.length; i++) {
	            customer_codes += checkStatus.data[i].customer_code+'|';
	        }
	        bg_admin_show('转交到号码池','./transferCustomer.html?customer_code='+customer_codes+'&id='+id,550,400)
	    });
	}

	function resetCallFailedNum () {
		// alert(id)
		$.ajax({
			type: 'post',
			url : "/index.php/crm/Outboundmanager/resetCallFailedNum", 
			data : 'task_id='+id,
			dataType : 'json',
			success : function (result) {
				if (result.success) {  
				    layer.alert(result.msg, {icon: 6}, function(index){
				        layer.close(index);
				    });
				} else {  
				    layer.alert(result.msg, {icon: 5}, function(index){
				        layer.close(index);
				    });
				}
			}
		})
	}


	$(function(){
		fishDialManager()
	})
	function fishDialManager() {
		$.ajax({
			type: 'post',
			url : "http://192.168.88.59:8888/index.php?m=Telemarketing&a=fishDialManager", 
			data : 'id='+id,
			dataType : 'json',
			success : function (result) {
				// alert(JSON.stringify(result))
				$('#ringingCount').html(result.ringingCount);
				$('#connectingCount').html(result.connectingCount);
				$('#waitQueue').html(result.waitQueue);
			}
		})
	}


	/**
	 * 修改并发
	 */
	function concurrenceChange(){
		var concurrent = $("#concurrent").val();
		// alert(concurrent);return false;
		// var url = "index.php?m=Telemarketing&a=concurrenceChange";
		var url = "http://192.168.88.59:8888/index.php?m=Telemarketing&a=concurrenceChange";
		var status = $("input[name='status']:checked").attr("value");
		if( status == 'off'){
			layer.alert("项目没有启动", {icon: 5}, function(index){
			    layer.close(index);
			});
		}else{
			//alert(concurrence);
			if( isNaN(concurrence) ){
				layer.alert("并发数必须为数字", {icon: 5}, function(index){
				    layer.close(index);
				});
			}else{
				$.ajax({
				  	type: 'POST',
				  	url: url,
				  	data: {id:id,concurrence:concurrence},
				  	success: function(result){
						 if(result=="ok"){
							 window.location.reload();
						 }else{
							 layer.alert(result, {icon: 5}, function(index){
							    layer.close(index);
							});
						 }
					}
				});
			}
		}
	}

</script>
</html>
